<?php
session_start();
if(isset($_SESSION['username'])){ 
	$user = $_SESSION['username'];
	$userid = $_SESSION['userid'];
	$new_name = $_POST['menu_name'];
	
	mysql_connect("localhost","yinch838","yinch838-09")	or die(`Could not connect: ` . mysql_error());
	@mysql_select_db("yinch838") or die(mysql_error());
	
	$query=utf8_encode("SELECT name FROM menu WHERE userid='$userid' AND name='$new_name'");
	$result = mysql_query($query) or die(mysql_error());
	if (mysql_numrows($result)>0){
		$message = "Finns redan en meny med namnet $new_name.";
	}
	elseif ($new_name != false){
		$query="INSERT INTO menu (name, userid) VALUES ('$new_name', '$userid')";
		mysql_query($query) or die(mysql_error());
		$message = "Menyn $new_name skapad.";
	}
	mysql_close();
	header("Location: ../php/restaurant.php?message=$message");
}

else{
	header("Location: ../xml/login.xml");
}
?>